package com.bjesc_b2c.app.appraiset.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.bjesc_b2c.app.appraiset.R;

import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.CommonAdapter;
import app.pinggushi.bjesc.com.baserecyclerview.adapter.base.ViewHolder;
import master_bean.CheckedCarItemBean;

/**
 * Created by lenovo on 2017/2/24.
 */

public class CheckedCarItemAdapter extends CommonAdapter<CheckedCarItemBean> implements View.OnClickListener {
    private int position;

    public CheckedCarItemAdapter(Context context, int layoutId, List<CheckedCarItemBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convertView(ViewHolder holder, CheckedCarItemBean bean, int position) {
        this.position = position;
        if (mDatas.size() == position + 1) {
            holder.setVisible(R.id.iv_photo_delete, false);
        } else {
            holder.setVisible(R.id.iv_photo_delete, true);
        }
        if(!TextUtils.isEmpty(bean.getPhoto())){
            if(bean.getPhoto().contains("http")){
                holder.setFrescoUrl(R.id.fresc_car_source_photo,bean.getPhoto(),true);
            }else{
                holder.setFrescoFile(R.id.fresc_car_source_photo,bean.getPhoto(),true);
            }
        }
        holder.setOnClickListener(R.id.iv_photo_delete, this);
    }

    @Override
    public void onClick(View view) {
        mDatas.set(position, new CheckedCarItemBean("", false));
        notifyDataSetChanged();
    }
}
